<?php


namespace paySdk\functions\postar\lib\Request\Body\Tag;


class Tag
{
    /* --- 必须参数 -------------------------------------------------------------------------------------------------- */
    // 机构号
    protected $agent_id;
    // 商户号
    protected $customer_id;
    // 时间戳，格式yyyyMMddHHmmss
    // 消费者ip
    protected $client_ip;
    protected $timestamp;
    // 版本号，可选值：1.0.0和2.0.0
    protected $version = "1.0.0";
    // 支付标识
    protected $pay_code;
    // 授权码
    protected $auth_code;

    public $available_parameters = ["agent_id", "customer_id", "client_ip", "timestamp", "pay_code",
        "auth_code"];
    public $parameters_from_caller;
    public $valid = false;

    public function __set($name, $value) {
        $this->$name = $value;
        if (! isset($this->parameters_from_caller[$name]))
            $this->parameters_from_caller[$name] = $value;
    }

    public function __get($name) {
        return $this->$name;
    }

    /**
     * 校验参数
     * @throws \Exception
     */
    public function chkParam() {
        var_dump($this->available_parameters);
        var_dump($this->parameters_from_caller);
        // 取$this->available_parameters与$this->parameters差集，判断是否有必须参数没有被传入
        if ([] !== $arr = array_diff($this->available_parameters, array_keys($this->parameters_from_caller)))
            throw new \Exception("取少必须参数参数(" . implode(",", $arr) . ")");

        $this->valid = true;
    }
}